<!DOCTYPE html>
<html>

<body>
    <form action="" name="nameForm">
        <label for="fname" style="background-color: aqua;">First name:</label>
        <button name="submit" onclick="checkName()">Submit</button>
        <input type="text" id="fname" name="fname">
        <br>

        <label for="lname" style="background-color: chartreuse;">Last name:</label>
        <input type="text" id="lname" name="lname">
        <br>
    </form>
    <script>
        function checkName() {
            var name = nameForm.lname.value;
            if (name == "") {
                alert("Please enter your name");
            }
        }
    </script>
</body>

</html>